#include "widget_setup_network.h"
#include <string>
#include <iostream>



network_setup_widget::network_setup_widget( QWidget* parent, Qt::WindowFlags flags ): setup_widget( parent, flags )
{	
	layout = new QVBoxLayout( this );


	QWidget* title_w = new QWidget( this );
	QHBoxLayout* title_w_l = new QHBoxLayout( title_w );

	QLabel* title_l = new QLabel( title_w );
	title_l->setTextFormat( Qt::RichText );
	title_l->setText( "<b><font size=8>Network Game Setup</font></b>" );
	title_w_l->addWidget( title_l );

	next_b = new QPushButton( "NEXT", title_w );
	next_b->setFixedWidth( 150 );
	next_b->setEnabled( false );
	title_w_l->addWidget( next_b );
	connect( next_b, SIGNAL( clicked() ), this, SLOT( next() ) );

	title_w->setLayout( title_w_l );
	layout->addWidget( title_w );


	QLabel* connect_l = new QLabel( this );
	connect_l->setTextFormat( Qt::RichText );
	connect_l->setText( "<b><font size=6>Connecting to the server</font></b>" );
	layout->addWidget( connect_l );


	QWidget* connect_w = new QWidget( this );
	QHBoxLayout* connect_w_l = new QHBoxLayout( connect_w );

	connect_i = new QLineEdit( connect_w );
	connect_i->setFixedWidth( 250 );
	connect_i->setText( "127.0.0.1" );
	connect_w_l->addWidget( connect_i );

	connect_b = new QPushButton( "Connect", connect_w );
	connect_b->setFixedWidth( 150 );
	connect_w_l->addWidget( connect_b );
	connect( connect_b, SIGNAL( clicked() ), this, SLOT( connect_server() ) );

	connect_w->setLayout( connect_w_l );
	layout->addWidget( connect_w );


	this->setLayout( layout );
};



void network_setup_widget::connect_server()
{
	bool connecting_successful = true;
	if( connecting_successful )
	{
		connect_b->setEnabled( false );
		connect_b->setText( "Connected!" );
		next_b->setEnabled( true );
	}
};



void network_setup_widget::next()
{
	game_gui* ggui = game_gui::get_instance();
	MyQScrollArea* sa = new MyQScrollArea( ggui->g );
	ggui->g->buy_w = new buy_widget( sa );
	sa->setSizeHint( ggui->g->buy_w->size() );
	sa->setWidget( ggui->g->buy_w );
	sa->setWidgetResizable( true );
	ggui->g->setCentralWidget( sa );
};